package com.walter.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import com.walter.dao.PersonalDao;
import com.walter.domain.Personal;
import com.walter.domain.TeacherInfo;
import com.walter.utils.HibernateUtils;

public class PersonalDaoImpl implements PersonalDao {

	@Override
	public Personal getById(long id) {
		// 1.获得session
		Session session = HibernateUtils.openSession();
		// 2.创建Criteria对象
		Criteria c = session.createCriteria(Personal.class);
		c.add(Restrictions.idEq(id));
		return (Personal) c.uniqueResult();
	}

	@Override
	public void saveInfo(Personal p) {
		// 1.获得session
		Session session = HibernateUtils.openSession();
		// 2.打开事务
		Transaction tx = session.beginTransaction();
		// 3.执行保存
		session.save(p);
		// 4.提交事务
		tx.commit();
		// 5.关闭资源
		session.close();
	}

	@Override
	public void updatePerson(Personal p) {
		// 1.获得session
		Session session = HibernateUtils.openSession();
		// 2.打开事务
		Transaction tx = session.beginTransaction();
		// 3.执行保存
		session.update(p);
		// 4.提交事务
		tx.commit();
		// 5.关闭资源
		session.close();

	}

}
